package juc;

import java.util.*;

/**
 * @author: feiwang_6
 * @create: 2020/7/13 10:57
 * @description:
 */
public class RangeTableIndex {
    private static HashMap<Integer, TreeSet<Integer>> result = new HashMap<>();
    
    public void putRangeTable(List<Integer> keys, List<Integer> values){
        if(keys == null || values == null){
            return;
        }
        
        for(int i = keys.get(0); i < keys.get(1); i++){
            TreeSet<Integer> entry = result.get(i);
            //初始化
            if(entry == null){
                TreeSet<Integer> set = new TreeSet<>(values);
                result.put(i, set);
            }else {
                entry.addAll(values);
            }
        }
    }
    
    //获取元素
    public TreeSet<Integer> getEntry(int key){
        return result.get(key);
    }
    
    public static void main(String[] args) {
        RangeTableIndex rangeTable = new RangeTableIndex();
        rangeTable.putRangeTable(Arrays.asList(1, 3), Arrays.asList(1, 2, 3, 4));
        
        System.out.println("get(1) " + rangeTable.getEntry(1));
        System.out.println("get(2) " + rangeTable.getEntry(2));
        /*rangeTable.putRangeTable(Arrays.asList(2,1000000), Arrays.asList(1,5,6,7));
        System.out.println("get(1) " + rangeTable.getEntry(1));
        System.out.println("get(2) " + rangeTable.getEntry(2));
        System.out.println("get(3) " + rangeTable.getEntry(3));*/
        
    }
}
